<template>
    <view class="content">
            <u--form
                    labelPosition="left"
                    :model="model1"
                    :rules="rules"
                    ref="uForm" labelWidth="100"
            >
                <!--                公司-->
                <view  v-show="model1.auth==='公司认证'" class="form" >

                    <u-form-item
                            :required="true"
                            label="联系人"
                            borderBottom
                            ref="item1"
                    >
                        <u--input
                                v-model="name"
                                disabledColor="#ffffff"
                                placeholder="请输入联系人"
                                border="none"
                        ></u--input>
                    </u-form-item>

                    <u-form-item
                            :required="true"
                            label="联系电话"
                            borderBottom
                            ref="item1"
                    >
                        <u--input
                                v-model="mobile"
                                disabledColor="#ffffff"
                                placeholder="请输入联系电话"
                                border="none"
                        ></u--input>
                    </u-form-item>
					<u-form-item
					        :required="true"
					        label="营业执照"
					        borderBottom
					        ref="item1"
					>
					    <view class="upload">
					        <u-upload
					        		:fileList="fileList1"
					        		@afterRead="afterRead"
					        		@delete="deletePic"
					        		name="1"
					        		:maxCount="9"
					        	></u-upload>
					    </view>
					
					</u-form-item>
					<u-form-item
					        :required="true"
					        label="内容"
					        borderBottom
					        ref="item1"
					>
					    <u--textarea
					            v-model="content"
					            disabledColor="#ffffff"
					            placeholder="请输入内容"
					            border="none"
					    ></u--textarea>
					</u-form-item>




        </view>
            </u--form>


        <u-action-sheet
            :show="showAuto"
            :actions="actions"
            title="选择认证方式"
            @close="showAuto = false"
            @select="authSelect"
        >
        </u-action-sheet>
<!--        <view class="footer">-->
            <u-button @click="submit" color="linear-gradient(90deg, #0096FF 0%, #003DB1 100%)" class="hande">提交认证</u-button>
<!--        </view>-->
    </view>
</template>
<script>
export default {
    name: 'index',
    components: {},
    data() {
        return {
            fileList1: [],
            model1: {
                auth:'公司认证',
                userInfo: {
                    name: 'uView UI',
                    sex: '',
                },
            },
            showAuto:false,
            rules: {
                'userInfo.name': {
                    type: 'string',
                    required: true,
                    message: '请填写姓名',
                    trigger: ['blur', 'change']
                },
                'userInfo.sex': {
                    type: 'string',
                    max: 1,
                    required: true,
                    message: '请选择男或女',
                    trigger: ['blur', 'change']
                },
            },
			name:"",
			idcard:"",
			company:"",
			address:"",
			people:"",
			mobile:"",
			type:0,
        }
    },
    methods: {
		submit(){
			var data = {}
			data.type= this.type
			if(this.type == 0){
				if(this.name == ""){
					this.$.ti_shi('请输入您的真实姓名');return;
				}
				data.name = this.name
				if(this.idcard == ""){
					this.$.ti_shi('请输入您的身份证号');return;
				}
				data.idcard = this.idcard
			}else{
				if(this.company == ""){
					this.$.ti_shi('请输入您的公司名称');return;
				}
				data.company = this.company
				var image = this.fileList1[0].url
				if(image == ""){
					this.$.ti_shi('请上传您的相关图片');return;
				}
				data.images = image
				if(this.address == ""){
					this.$.ti_shi('请输入您的公司地址');return;
				}
				data.address = this.address
				if(this.people == ""){
					this.$.ti_shi('请输入您的联系人');return;
				}
				data.people = this.people
				if(this.mobile == ""){
					this.$.ti_shi('请输入您的联系电话');return;
				}
				data.mobile = this.mobile
			}
			this.$.ajax(1,"POST","user/setfranchisees",data,(res)=>{
				this.$.ti_shi(res.msg)
				if(res.code == 1){
					setTimeout(()=>{
						uni.navigateBack()
					},1000)
				}
				console.log(res)
			})
		},
        authSelect(e) {
            this.model1.auth = e.name
			this.type = e.type
            this.$refs.uForm.validateField('auth')
        },
		deletePic(event) {
			this[`fileList${event.name}`].splice(event.index, 1)
		},
		// 新增图片
		async afterRead(event) {
			// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
			let lists = [].concat(event.file)
			let fileListLen = this[`fileList${event.name}`].length
			lists.map((item) => {
				this[`fileList${event.name}`].push({
					...item,
					status: 'uploading',
					message: '上传中'
				})
			})
			for (let i = 0; i < lists.length; i++) {
				const result = await this.uploadFilePromise(lists[i].url)
				let item = this[`fileList${event.name}`][fileListLen]
				this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
					status: 'success',
					message: '',
					url: result
				}))
				fileListLen++
			}
		},
		uploadFilePromise(url) {
			var that = this
			return new Promise((resolve, reject) => {
				let a = uni.uploadFile({
					url: that.$.ajax_url+'index/upload', // 仅为示例，非真实的接口地址
					filePath: url,
					name: 'file',
					formData: {
						user: 'test'
					},
					success: (res) => {
						console.log(   )
						// setTimeout(() => {
							resolve(JSON.parse(res.data).data.url)
						// }, 1000)
					}
				});
			})
		},
    },
    created() {

    },
    mounted() {

    },
}
</script>
<style lang="scss" scoped>
.content {

  margin: 20rpx 20rpx 20rpx;
  .notice{
    background-color: #FFF7EB;
    font-size: 28rpx;
    font-weight: 400;
    padding: 5rpx 30rpx;
    height: 80rpx;
    line-height: 80rpx;
    margin-bottom: 20rpx;
    margin-top: -30rpx;
    color: #FF4435;

  }
  .form{
    background-color: #fff;
    border-radius: 12rpx;
    padding: 20rpx 30rpx 0;
    margin: 30rpx 0;
    .upload{
      display: flex;
      flex-direction: column;
      gap: 20rpx;
      color: #999999;
      font-size: 12px;
      font-weight: 400;
    }
  }

  .footer {
    padding: 20rpx;
    position: fixed;
    bottom: 0;
    width: 100%;

    .hande {
      color: #FFFFFF;
      border-radius: 6px;
      font-size: 13px;
    }

  }
}
</style>

